/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {
    multipart: {
      mode: 'file',
    },
  };

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1614687985525_3043';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    middleware: [ 'errorHandler' ],
    mongoose: {
      client: {
        url: 'mongodb://127.0.0.1:27017/blog',
        options: {
          useUnifiedTopology: true,
        },
      },
    },
    security: {
      csrf: {
        enable: false,
      },
    },
    cors: {
      // 写法 * 的 polyfill
      origin: ctx => {
        return ctx.header.origin;
      },
      credentials: true,
      allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
    },
    io: {
      init: { }, // passed to engine.io
      namespace: {
        '/': {
          connectionMiddleware: [ 'connection' ],
        },
      },
    },
  };
  return {
    ...config,
    ...userConfig,
  };
};
